
import junit.framework.Assert;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * 
 */

/**
 * @author awhillans11
 *
 */
public class firstTest {

	booleanSchedule student1 = new booleanSchedule();
	booleanSchedule adviser1 = new booleanSchedule();
	finalSchedule meetingSchedule = new finalSchedule();
	
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		booleanSchedule student1 = new booleanSchedule();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		student1 = null;
	}
	
	@Test
	public void  initializeBooleanScheduleTest()
	{

		
		Assert.assertFalse(student1.getAvailable(0));
		Assert.assertFalse(student1.getAvailable(55));
	}
	
	@Test
	public void  checkSetMeetTime()
	{
		milTimeSchedule timeSchedule;
		
		timeSchedule = new milTimeSchedule();
		
		timeSchedule.setMinimumMeetTime(4);
		
		Assert.assertEquals(4,timeSchedule.getMeetTime());
		
	}
	@Test
	public void  compareSchedules(){
		milTimeSchedule student = new milTimeSchedule();
		milTimeSchedule adviser = new milTimeSchedule();
		student.setAvailable(800, 830);
		student.setAvailable(915, 1000);
		student1.generateSchedule(student);
		
		adviser.setAvailable(800, 900);
		adviser.setAvailable(930, 1000);
		adviser1.generateSchedule(adviser);
		// they should overlap at 800-830
		booleanSchedule resultSchedule = new booleanSchedule();
		for (int count=0; count<56; count++){
			if(student1.getAvailable(count) == true && adviser1.getAvailable(count)==true){
				resultSchedule.setAvailable(count);
			}			
		}
		//915 and 1000 should be false, 930 945 should be true
		Assert.assertFalse(resultSchedule.getAvailable(5));
		Assert.assertTrue(resultSchedule.getAvailable(6));
		Assert.assertTrue(resultSchedule.getAvailable(7));
		Assert.assertFalse(resultSchedule.getAvailable(8));
		
	}
	@Test
	public void testBoolToMilSingleSlot(){
		milTimeSchedule mil = new milTimeSchedule();
		booleanSchedule original =  new booleanSchedule();
		original.setAvailable(2);
		original.setAvailable(3);
		original.setAvailable(4);
		original.setAvailable(5);
		
		mil = original.getMilTimeSchedule();
		
		Assert.assertEquals(830, mil.getStart(0));
		Assert.assertEquals(930, mil.getEnd(0));
	}
	
	@Test
	public void testBoolToMilTwoSlots(){
		milTimeSchedule mil = new milTimeSchedule();
		booleanSchedule original =  new booleanSchedule();
		original.setAvailable(2);
		original.setAvailable(3);
		original.setAvailable(4);
		original.setAvailable(5);
		
		original.setAvailable(15);
		original.setAvailable(16);
		original.setAvailable(17);
		
		
		mil = original.getMilTimeSchedule();
		
		Assert.assertEquals(830, mil.getStart(0));
		Assert.assertEquals(930, mil.getEnd(0));
		
		Assert.assertEquals(1145, mil.getStart(1));
		Assert.assertEquals(1230, mil.getEnd(1));

	}
	
	@Test
	public void testBoolToMilSingleSlotToEnd(){
		milTimeSchedule mil = new milTimeSchedule();
		booleanSchedule original =  new booleanSchedule();
		original.setAvailable(52);
		original.setAvailable(53);
		original.setAvailable(54);
		original.setAvailable(55);
		
		mil = original.getMilTimeSchedule();
		
		Assert.assertEquals(2100, mil.getStart(0));
		Assert.assertEquals(2200, mil.getEnd(0));

	}
	
	@Test
	public void testBoolToMilSingleSlotStartToEnd(){
		milTimeSchedule mil = new milTimeSchedule();
		booleanSchedule original =  new booleanSchedule();
		
		for(int all=0;all<56;all++)
		{
			original.setAvailable(all);
		}
		
		mil = original.getMilTimeSchedule();
		
		Assert.assertEquals(800, mil.getStart(0));
		Assert.assertEquals(2200, mil.getEnd(0));

	}
	
	@Test
	public void testBoolToMilMultipleSlots(){
		milTimeSchedule mil = new milTimeSchedule();
		booleanSchedule original =  new booleanSchedule();
		
		for(int all=0;all<56;all++)
		{
			original.setAvailable(all);
		}
		
		original.setUnavailable(10);
		original.setUnavailable(36);
		original.setUnavailable(44);
		
		mil = original.getMilTimeSchedule();
		
		Assert.assertEquals(800, mil.getStart(0));
		Assert.assertEquals(1030, mil.getEnd(0));
		
		Assert.assertEquals(1045, mil.getStart(1));
		Assert.assertEquals(1700, mil.getEnd(1));
		
		Assert.assertEquals(1715, mil.getStart(2));
		Assert.assertEquals(1900, mil.getEnd(2));
		
		Assert.assertEquals(1915, mil.getStart(3));
		Assert.assertEquals(2200, mil.getEnd(3));


	}
	@Test
	public void  checkAvailableScheduleTest()
	{
		milTimeSchedule timeSchedule;
		
		timeSchedule = new milTimeSchedule();
		timeSchedule.setAvailable(800, 845);
		timeSchedule.setAvailable(915,945);
		//800-830 means that boolSchedule[0,1] should be true and nothing else
		student1.generateSchedule(timeSchedule);
		
//		timeSchedule.setAvailable(900, 930);
//		student1.generateSchedule(timeSchedule);
		Assert.assertTrue(student1.getAvailable(0));
		Assert.assertFalse(student1.getAvailable(3));
		Assert.assertTrue(student1.getAvailable(5));
		Assert.assertTrue(student1.getAvailable(6));
		Assert.assertFalse(student1.getAvailable(7));
	}
        @Test
        public void testBoolToMilMultipleSlotsNoCommonSlots(){
                milTimeSchedule studentMil = new milTimeSchedule();
                booleanSchedule studentBool =  new booleanSchedule();
                
              //  milTimeSchedule advisorMil = new milTimeSchedule();
                //booleanSchedule advisorBool =  new booleanSchedule();
                
                for(int all=0;all<56;all++)
                {
                        studentBool.setAvailable(all);
                }
                
                studentBool.setUnavailable(2);
                studentBool.setUnavailable(3);
                studentBool.setUnavailable(4);
                
                //advisorBool.setAvailable(2);
                //advisorBool.setAvailable(3);
                //advisorBool.setAvailable(4);
                
                studentMil = studentBool.getMilTimeSchedule();
                //advisorMil = advisorBool.getMilTimeSchedule();
                
                Assert.assertEquals(800, studentMil.getStart(0));
                Assert.assertEquals(830, studentMil.getEnd(0));
   

                
        }
	@Test
	public void  compareSchedulesSameSchedulesBoolToMil(){
		milTimeSchedule student = new milTimeSchedule();
		milTimeSchedule adviser = new milTimeSchedule();
		booleanSchedule studentBool =  new booleanSchedule();
		booleanSchedule adviserBool =  new booleanSchedule();
		//900 to 1030
		for (int count=4; count<10; count++){			
				studentBool.setAvailable(count);
				adviserBool.setAvailable(count);		
		}		
		//1200 - 1345
		for (int count=16; count<23; count++){			
			studentBool.setAvailable(count);
			adviserBool.setAvailable(count);		
		}
		student = studentBool.getMilTimeSchedule();
		adviser = adviserBool.getMilTimeSchedule();

		Assert.assertEquals(student.getStart(0), adviser.getStart(0));
		Assert.assertEquals(student.getEnd(1), adviser.getEnd(1));
		
		
	}
	        @Test
        public void checkConvertMiltoSlot(){
            
                milTimeSchedule advisorMil =  new milTimeSchedule();
                
    Assert.assertEquals(0, advisorMil.milTimeToSlot(800));
                Assert.assertEquals(40, advisorMil.milTimeToSlot(1800));
                  
        }
	@Test
	public void testMinMeetTime(){
		milTimeSchedule student = new milTimeSchedule();
		milTimeSchedule adviser = new milTimeSchedule();
		booleanSchedule boolStudent = new booleanSchedule();
		booleanSchedule boolAdviser = new booleanSchedule();
		booleanSchedule resultSchedule = new booleanSchedule();
		student.setAvailable(1000, 1015);
		adviser.setAvailable(1000, 1045);
		boolStudent.generateSchedule(student);
		boolAdviser.generateSchedule(adviser);
		for (int count=0; count<56; count++){
			if(boolStudent.getAvailable(count) == true && boolAdviser.getAvailable(count)==true){
				resultSchedule.setAvailable(count);
			}			
		}
		milTimeSchedule newSchedule = resultSchedule.getMilTimeSchedule();
		//make sure that available time wasn't set between 1000 and 1045
		Assert.assertEquals(0, newSchedule.getStart(0));
	}
	    @Test
    public void testAllSlotsMatch()
    {
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule result = new booleanSchedule();
    	 for(int all=0;all<56;all++)
         {
                 student.setAvailable(all);
                 advisor.setAvailable(all);
                 if(student.getAvailable(all)==true && advisor.getAvailable(all)){
                	 result.setAvailable(all);
                 }
         }
    	 Assert.assertTrue(result.getAvailable(0));
    	 Assert.assertTrue(result.getAvailable(5));
    	 Assert.assertTrue(result.getAvailable(40));
    	 Assert.assertTrue(result.getAvailable(51));
    }
    @Test
    public void testTwoDifferentSlotsMatch()
    {
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule result = new booleanSchedule();
    	
    	student.setAvailable(0);
    	student.setAvailable(1);
    	student.setAvailable(21);
    	student.setAvailable(22);
    	student.setAvailable(23);
    	student.setAvailable(24);
    	student.setAvailable(40);
    	student.setAvailable(41);

    	advisor.setAvailable(0);
    	advisor.setAvailable(1);
    	advisor.setAvailable(2);
    	advisor.setAvailable(3);
    	advisor.setAvailable(21);
    	advisor.setAvailable(22);
    	advisor.setAvailable(40);
    	advisor.setAvailable(41);
    	
    	for(int i=0;i<56;i++){
    		if(student.getAvailable(i)==true && advisor.getAvailable(i)==true){
    			result.setAvailable(i);
    		}
    	}
    	
    	Assert.assertTrue(result.getAvailable(0));
   	 	Assert.assertTrue(result.getAvailable(1));
   	 	Assert.assertTrue(result.getAvailable(21));
   	 	Assert.assertTrue(result.getAvailable(22));
   	 	Assert.assertTrue(result.getAvailable(40));
   	 	Assert.assertFalse(result.getAvailable(23));
   	 	Assert.assertFalse(result.getAvailable(3));
   	 	Assert.assertFalse(result.getAvailable(33));
    }
    @Test
    public void testContraryTimeSlots(){
    	booleanSchedule b = new booleanSchedule();
    	b.setAvailable(4);
    	b.setAvailable(5);
    	b.setUnavailable(5);
    	b.setUnavailable(6);
    	milTimeSchedule m = b.getMilTimeSchedule(15); // pass thru 15
    												// to change the default minimum meet time
    	Assert.assertFalse(b.getAvailable(5));
    	Assert.assertEquals(900, m.getStart(0));
    	Assert.assertEquals(915, m.getEnd(0));
    }
    
    @Test
    public void testSimpleNoMeetingSlots(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	student.setAvailable(4);
    	student.setAvailable(5);
    	
    	advisor.setAvailable(16);
    	advisor.setAvailable(17);
    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
 
    	for (int slotCount=0; slotCount<56; slotCount++)
    	{
    		Assert.assertFalse(resultSchedule.getAvailable(slotCount));
    	}

    }
    
    @Test
    public void testAlternatingNoMeetingSlots(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=0; slotCount<56; slotCount+=2)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=1; slotCount<56; slotCount+=2)
    	{
    		advisor.setAvailable(slotCount);
    	}   	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
 
    	for (int slotCount=0; slotCount<56; slotCount++)
    	{
    		Assert.assertFalse(resultSchedule.getAvailable(slotCount));
    	}

    }
    
    @Test
    public void testFrontBackNoMeetingSlots(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=0; slotCount<26; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=26; slotCount<56; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	}   	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
 
    	for (int slotCount=0; slotCount<56; slotCount++)
    	{
    		Assert.assertFalse(resultSchedule.getAvailable(slotCount));
    	}

    }
    
    @Test
    public void testSmallComplexOverlapMeetingSlots(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=0; slotCount<27; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=26; slotCount<56; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	}   	
    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
  	
  	for (int slotCount=0; slotCount<56; slotCount++)
    	{
  			if (slotCount != 26)
  			{
  				Assert.assertFalse(resultSchedule.getAvailable(slotCount));
  			}
  			else
  			{
  				Assert.assertTrue(resultSchedule.getAvailable(slotCount));
  			}
    	}

    }
    
    @Test
    public void testOverlapMeetingSlotsAtBeginning(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=0; slotCount<34; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=0; slotCount<37; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	}   	
    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
  	
  	for (int slotCount=0; slotCount<38; slotCount++)
    	{
  			if (slotCount > 33)
  			{
  				Assert.assertFalse(resultSchedule.getAvailable(slotCount));
  			}
  			else
  			{
  				Assert.assertTrue(resultSchedule.getAvailable(slotCount));
  			}
    	}

    }
    
    @Test
    public void testOverlapMeetingSlotsAtEnd(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=30; slotCount<56; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=37; slotCount<56; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	}   	
    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
  	
  	for (int slotCount=0; slotCount<56; slotCount++)
    	{
  			if (slotCount < 37)
  			{
  				Assert.assertFalse(resultSchedule.getAvailable(slotCount));
  			}
  			else
  			{
  				Assert.assertTrue(resultSchedule.getAvailable(slotCount));
  			}
    	}

    }
    
    @Test
    public void testOverlapMeetingSlotsAtEnds(){
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	
    	for (int slotCount=0; slotCount<20; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=0; slotCount<27; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	} 
    	
    	for (int slotCount=30; slotCount<56; slotCount++)
    	{
    		student.setAvailable(slotCount);
    	}
    	
    	for (int slotCount=37; slotCount<56; slotCount++)
    	{
    		advisor.setAvailable(slotCount);
    	}   	

    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor, student);
  	
  	for (int slotCount=0; slotCount<56; slotCount++)
    	{
  			if (slotCount < 20 || slotCount > 36)
  			{
  				Assert.assertTrue(resultSchedule.getAvailable(slotCount));
  			}
  			else
  			{
  				Assert.assertFalse(resultSchedule.getAvailable(slotCount));
  			}
    	}

    }
    @Test
	public void testMilScheduleToBoolScheduleMethod(){
    	milTimeSchedule m = new milTimeSchedule();
    	booleanSchedule b = new booleanSchedule();
    	
    	m.setAvailable(930, 1200);
    	m.setAvailable(1400, 1515);
    	m.setAvailable(1700, 2200);

    	b = m.getBoolSchedule();
    	
    	System.out.println(b.getAvailable(11));
    	Assert.assertTrue(b.getAvailable(11));
    	
    	Assert.assertTrue(b.getAvailable(26));
    	Assert.assertTrue(b.getAvailable(47));
    	Assert.assertFalse(b.getAvailable(2));
    	Assert.assertFalse(b.getAvailable(18));
    	Assert.assertFalse(b.getAvailable(30));
    }
    
    @Test
    public void testSimleMilScheduleFindMeetingTimes(){
    	milTimeSchedule student = new milTimeSchedule();
    	milTimeSchedule advisor = new milTimeSchedule();
    	booleanSchedule resultSchedule = new booleanSchedule();
    	milTimeSchedule resultMilSchedule = new milTimeSchedule();
    	
    	student.setAvailable(1300, 1430);
    	advisor.setAvailable(1330,1600);
    	
    	
    	resultSchedule = meetingSchedule.findCommonMeetingTimes(advisor.getBoolSchedule(), student.getBoolSchedule());
    	resultMilSchedule = resultSchedule.getMilTimeSchedule();
  	
    	Assert.assertEquals(1330, resultMilSchedule.getStart(0));
    	Assert.assertEquals(1430, resultMilSchedule.getEnd(0));
    }
    
    @Test
    public void testMilTimeSchedGetStart(){
    	milTimeSchedule m = new milTimeSchedule();
    	m.setAvailable(830, 900);
    	m.setAvailable(830, 930);
    	
    	Assert.assertEquals(830, m.getStart(0));
    	Assert.assertEquals(830, m.getStart(1));
    }
    
    @Test
    public void useGenerateResult(){
    	milTimeSchedule studentMilMon = new milTimeSchedule();
    	milTimeSchedule adviserMilMon = new milTimeSchedule();
    	milTimeSchedule compatibleMilMon = new milTimeSchedule();
    	studentMilMon.setAvailable(900, 1000);
    	studentMilMon.setAvailable(1400, 1530);
    	
    	adviserMilMon.setAvailable(930, 1030);
    	adviserMilMon.setAvailable(1500, 1700);
    	
    	compatibleMilMon = meetingSchedule.generateResultMilSchedule(adviserMilMon, studentMilMon);
    	
    	Assert.assertEquals(930, compatibleMilMon.getStart(0));
    	Assert.assertEquals(1000, compatibleMilMon.getEnd(0));
    	Assert.assertEquals(1500, compatibleMilMon.getStart(1));
    	Assert.assertEquals(1530, compatibleMilMon.getEnd(1));
    	
    }
    @Test
    public void useGenerateResultWithMinMeetTime(){
    	milTimeSchedule studentMilMon = new milTimeSchedule();
    	milTimeSchedule adviserMilMon = new milTimeSchedule();
    	milTimeSchedule compatibleMilMon = new milTimeSchedule();
    	studentMilMon.setAvailable(900, 1000);
    	studentMilMon.setAvailable(1400, 1530);
    	
    	adviserMilMon.setAvailable(945, 1030);
    	adviserMilMon.setAvailable(1515, 1700);
    	
    	compatibleMilMon = meetingSchedule.generateResultMilSchedule(adviserMilMon, studentMilMon, 15);
    	
    	Assert.assertEquals(945, compatibleMilMon.getStart(0));
    	Assert.assertEquals(1000, compatibleMilMon.getEnd(0));
    	Assert.assertEquals(1515, compatibleMilMon.getStart(1));
    	Assert.assertEquals(1530, compatibleMilMon.getEnd(1));
    	
    }
//    @Test
//    public void createEntireSchedule(){
//    	milTimeSchedule studentMon, studentTues, studentWeds, studentThurs, studentFri;
//    	milTimeSchedule adviserMon, adviserTues, adviserWeds, adviserThurs, adviserFri = new milTimeSchedule();
//    	studentMon = new milTimeSchedule();
//    	adviserMon = new milTimeSchedule();
//    	studentMon.setAvailable(1000, 1100);
//    	studentMon.setAvailable(1400, 1530);
//    	adviserMon.setAvailable(1030, 1115);
//    	
//    	
//    }
    
}

